package com.bao.student.dao.impl;

import com.bao.student.dao.StudentDao;
import com.bao.student.entity.Student;

import java.util.ArrayList;

public class StudentDaoImpl implements StudentDao {
    /**
     * 添加学生
     * @param newStudent service生成的学生信息
     */
    @Override
    public void addStudent(Student newStudent) {

        if (students.add(newStudent)) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }

    /**
     * 删除学生信息
     *
     * @param index service找到的索引
     */
    @Override
    public void deleteStudent(int index) {
            students.remove(index);
            System.out.println("删除成功");

    }

    /**
     * 修改学生
     * @param newStudent service生成的学生类
     * @param index 需要修改的索引
     */
    @Override
    public void updateStudent(Student newStudent,int index) {
                students.set(index, newStudent);
    }

    /**
     * 查询所有学生信息3
     */
    @Override
    public void findAllStudent() {
        for (Student student : students) {
            System.out.println(student.toString());
        }

    }
}
